<!DOCTYPE html>
<html>
<head>
    <title>{{ title }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            border-radius: 10px;
            margin-bottom: 30px;
            text-align: center;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            background: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        th, td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        th {
            background-color: #f8f9fa;
            font-weight: bold;
            color: #495057;
        }

        tr:hover {
            background-color: #f8f9fa;
        }

        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            font-size: 14px;
            margin: 2px;
        }

        .btn-edit {
            background-color: #28a745;
            color: white;
        }

        .btn-delete {
            background-color: #dc3545;
            color: white;
        }

        .btn-add {
            background-color: #007bff;
            color: white;
            padding: 12px 24px;
            margin-bottom: 20px;
        }

        .actions {
            display: flex;
            gap: 5px;
        }

        .empty-state {
            text-align: center;
            padding: 40px;
            background: white;
            border-radius: 10px;
            margin: 20px 0;
        }
    </style>
</head>
<body>
<div class="header">
    <h1>🎓 {{ title }}</h1>
    <p>学生信息管理系统 - 共 {{ students.count }} 名学生</p>
</div>

<a href="{% url 'student_add' %}" class="btn btn-add">➕ 添加新学生</a>
<!-- 搜索框 -->
<div style="margin-bottom: 20px;">
    <form method="get" action="{% url 'student_list' %}" class="search-form">
        <input type="text" name="q" placeholder="搜索姓名或学号..."
               value="{{ request.GET.q }}" style="padding: 8px; width: 300px;">
        <button type="submit"
                style="padding: 8px 16px; background: #007bff; color: white; border: none; border-radius: 4px;">
            🔍 搜索
        </button>
        {% if request.GET.q %}
        <a href="{% url 'student_list' %}" style="margin-left: 10px; color: #666;">清除搜索</a>
        {% endif %}
    </form>
</div>
{% if search_query %}
<div style="background: #e7f3ff; padding: 10px; border-radius: 5px; margin-bottom: 15px;">
    📊 搜索 "{{ search_query }}" 的结果：找到 {{ students.count }} 名学生
</div>
{% endif %}
{% if students %}
<table>
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>学号</th>
        <th>年龄</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {% for student in students %}
    <tr>
        <td>{{ student.id }}</td>
        <td><strong>{{ student.name }}</strong></td>
        <td>{{ student.student_id }}</td>
        <td>{{ student.age }}</td>
        <td>{{ student.created_time|date:"Y-m-d H:i" }}</td>
        <td class="actions">
            <a href="{% url 'student_edit' student.id %}" class="btn btn-edit">✏️ 编辑</a>
            <a href="{% url 'student_delete' student.id %}" class="btn btn-delete"
               onclick="return confirm('确定要删除学生 {{ student.name }} 吗？')">🗑️ 删除</a>
        </td>
    </tr>
    {% endfor %}
    </tbody>
</table>
{% else %}
<div class="empty-state">
    <h3>📝 还没有学生信息</h3>
    <p>点击上方的"添加新学生"按钮来添加第一个学生</p>
</div>
{% endif %}
<!-- 分页控件 -->
{% if students.paginator.num_pages > 1 %}
<div style="margin-top: 20px; text-align: center;">
    <div class="pagination">
        {% if students.has_previous %}
            <a href="?page=1{% if search_query %}&q={{ search_query }}{% endif %}" class="btn">« 第一页</a>
            <a href="?page={{ students.previous_page_number }}{% if search_query %}&q={{ search_query }}{% endif %}" class="btn">‹ 上一页</a>
        {% endif %}

        <span style="margin: 0 15px;">
            第 {{ students.number }} 页，共 {{ students.paginator.num_pages }} 页
        </span>

        {% if students.has_next %}
            <a href="?page={{ students.next_page_number }}{% if search_query %}&q={{ search_query }}{% endif %}" class="btn">下一页 ›</a>
            <a href="?page={{ students.paginator.num_pages }}{% if search_query %}&q={{ search_query }}{% endif %}" class="btn">最后一页 »</a>
        {% endif %}
    </div>
</div>
{% endif %}
</body>
</html>